//
//  HMFirstCell.m
//  学习的时长
//
//  Created by 李贺 on 2017/1/8.
//  Copyright © 2017年 李贺. All rights reserved.
//

#import "HMFirstCell.h"
#import <Masonry.h>
#import "UILabel+Addition.h"
#import "HMSetInformationViewController.h"
@implementation HMFirstCell

// 重写父类的初始化方法,在此方法中添加cell中的子控件
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 添加子控件
        [self setupUI];
    }
    return self;
}

#pragma mark - 添加cell中的子控件

- (void)setupUI {
    UIView * infoView = [[UIView alloc] init];
    
    [self.contentView addSubview:infoView];
    
    [infoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.contentView);
    }];
    
    
    UILabel * learnTimeLable = [UILabel hm_labelWithText:@"学习时间"fontSize:k_FONT_SMALL color:[UIColor darkGrayColor] TextAlignment:NSTextAlignmentCenter];
    
    UILabel * readBookLable = [UILabel hm_labelWithText:@"阅读书籍" fontSize:k_FONT_SMALL color:[UIColor darkGrayColor] TextAlignment:NSTextAlignmentCenter];
    
    UILabel * continuouStudyLable = [UILabel hm_labelWithText:@"连续学习" fontSize:k_FONT_SMALL color:[UIColor darkGrayColor] TextAlignment:NSTextAlignmentCenter];
    
    UILabel * recordLearnTimeLable = [UILabel hm_labelWithText:@"8小时17分" fontSize:k_FONT_NORMAL color:[UIColor blackColor] TextAlignment:NSTextAlignmentCenter];
    
    UILabel * recordReadBookLable = [UILabel hm_labelWithText:@"2本" fontSize:k_FONT_NORMAL color:[UIColor blackColor] TextAlignment:NSTextAlignmentCenter];
    
    UILabel * recordContinuouStudyLable = [UILabel hm_labelWithText:@"0天" fontSize:k_FONT_NORMAL color:[UIColor blackColor] TextAlignment:NSTextAlignmentCenter];
    
    NSString *str2 = [[[HMSetInformationViewController alloc]init] getPhotoFilePathWithNSString:@"name"];
    NSString *str = [NSString stringWithContentsOfFile:str2 encoding:NSUTF8StringEncoding error:nil];
    
    UILabel *nameLable = [UILabel hm_labelWithText:str fontSize:k_FONT_BIG color:[UIColor blackColor]];
    
    [infoView addSubview:learnTimeLable];
    [infoView addSubview:readBookLable];
    [infoView addSubview:continuouStudyLable];
    [infoView addSubview:recordLearnTimeLable];
    [infoView addSubview:recordReadBookLable];
    [infoView addSubview:recordContinuouStudyLable];
    [infoView addSubview:nameLable];
    
    [learnTimeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(infoView.mas_left).offset(16);
        make.bottom.equalTo(infoView.mas_bottom).offset(-8);
    }];
    
    [readBookLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(learnTimeLable);
        make.width.equalTo(learnTimeLable.mas_width);
        make.left.equalTo(learnTimeLable.mas_right).offset(0);
    }];
    
    [continuouStudyLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(infoView.mas_right).offset(-8 * 2);
        make.centerY.equalTo(learnTimeLable);
        make.width.equalTo(learnTimeLable.mas_width);
        make.left.equalTo(readBookLable.mas_right).offset(0);
    }];
    
    
    [recordLearnTimeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(infoView.mas_left).offset(8 * 2);
        make.bottom.equalTo(learnTimeLable.mas_top).offset(-8);
    }];
    
    [recordReadBookLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(recordLearnTimeLable);
        make.width.equalTo(recordLearnTimeLable.mas_width);
        make.left.equalTo(recordLearnTimeLable.mas_right).offset(0);
    }];
    
    [recordContinuouStudyLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(infoView.mas_right).offset(-8 * 2);
        make.centerY.equalTo(recordLearnTimeLable);
        make.width.equalTo(recordLearnTimeLable.mas_width);
        make.left.equalTo(recordReadBookLable.mas_right).offset(0);
    }];
    
    [nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(infoView);
        make.bottom.equalTo(recordReadBookLable.mas_top).offset(-8);
    }];
    
    UIImageView * headView = [[UIImageView alloc] init];
    [infoView addSubview:headView];
    headView.backgroundColor = [UIColor lightGrayColor];
    
    NSString * path = [[[HMSetInformationViewController alloc]init] getPhotoFilePath];
    UIImage * pathImage = [UIImage imageWithContentsOfFile:path];
    headView.image = pathImage;
    
    //切圆
    headView.layer.cornerRadius = 25;
    headView.clipsToBounds = YES;
    [headView.layer masksToBounds];
    
    headView.contentMode = UIViewContentModeScaleToFill;
    [headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(infoView);
        make.bottom.equalTo(nameLable.mas_top).offset(-8);
        make.width.height.offset(50);
    }];

}

@end
